package com.x.uikit.page;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

public class PageUtils {
    public static void set(Activity activity) {
        int lastVis = activity.getWindow().getDecorView().getSystemUiVisibility();

    }

    public static void setStatusBarMode(boolean isDark) {

    }

    public static void showStatusBar(Context context) {
        if (!(context instanceof Activity)) {
            return;
        }
        Activity activity = (Activity) context;
        View view = activity.getWindow().getDecorView();
        int vis = view.getSystemUiVisibility();
//         vis |=View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
//        vis |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
        vis &= ~View.SYSTEM_UI_FLAG_FULLSCREEN;
        vis |= View.SYSTEM_UI_FLAG_VISIBLE;
        setSystemUiVisibility(view, vis);
    }

    public static void hideStatusBar(Context context) {
        if (!(context instanceof Activity)) {
            return;
        }
        Activity activity = (Activity) context;
        View view = activity.getWindow().getDecorView();
//        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        int vis = view.getSystemUiVisibility();
        vis |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
        vis |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
        vis |= View.SYSTEM_UI_FLAG_FULLSCREEN;
//        setSystemUiVisibility(view, vis);
        final Window window = activity.getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }

    private static void setSystemUiVisibility(View view, int vis) {
        if (view == null) {
            return;
        }
        int lastVis = view.getSystemUiVisibility();
        if (lastVis == vis) {
            return;
        }
        view.setSystemUiVisibility(vis);
    }
}
